# tools/scripts/check_raspberry.py
import sys

import paramiko


def check_raspberry_status(host, username, password):
    """检查树莓派状态."""
    try:
        ssh = paramiko.SSHClient()
        ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
        ssh.connect(host, username=username, password=password)

        # 检查系统状态
        commands = [
            "vcgencmd measure_temp",  # CPU温度
            "free -h",  # 内存使用
            "df -h",  # 磁盘使用
            "top -bn1 | grep load",  # CPU负载
        ]

        for cmd in commands:
            stdin, stdout, stderr = ssh.exec_command(cmd)
            print(f"\n=== {cmd} ===")
            print(stdout.read().decode())

    except Exception as e:
        print(f"Error: {e!s}")
    finally:
        ssh.close()


if __name__ == "__main__":
    if len(sys.argv) != 4:
        print("Usage: python check_raspberry.py <host> <username> <password>")
        sys.exit(1)

    host = sys.argv[1]
    username = sys.argv[2]
    password = sys.argv[3]
    check_raspberry_status(host, username, password)
